<template>
  <div style="text-align: center;">
    <!-- <HelloWorld></HelloWorld>
    {{ randomStr }} -->

    <img src="@/assets/RyderLogo.png" />
    <h2>手机微信扫码授权登陆</h2>
    <div v-loading="loading" :style="[{'width':size+'px'},{'height':size+'px'},{'margin':'auto'}]">
      <vue-qr logoSrc="img/basicprofile2.jpg" :text="RYD_LoginUrl" :size="size" v-if="!loading"></vue-qr>
    </div>

  </div>
</template>

<script setup>
import { useWindowSize } from '@vant/use';
import { ref, watch } from 'vue';
import vueQr from 'vue-qr/src/packages/vue-qr.vue'
import axios from '@/utils/axios'

// // @ is an alias to /src
// import HelloWorld from "@/components/HelloWorld.vue";
// import { inject, ref } from "vue";
// import { random } from "nanoid";
// export default {
//   name: "HomeView",
//   components: {
//     HelloWorld,
//   },
// };
let RYD_LoginId = "";
let RYD_LoginUrl = ref("");
let loading = ref(true);
axios({
  url: "/api/QRLogin",
  method: "Post"
}).then(res => {
  if (res != "" && res != null) {
    RYD_LoginId = res;
    var ObjectList = '{"RYD_LoginId":"'+RYD_LoginId+'"}'
    var ObjectListStr = encodeURIComponent(ObjectList);
    RYD_LoginUrl.value = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaa3744f6b6f630f2&redirect_uri=http://hrms.ryderems.com/itsm.html?ObjectList=" + ObjectListStr + "&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect";
    console.log(RYD_LoginUrl.value)
    loading.value = false;
    queryQRLogin();
  }

})
let timer = 0;
let queryQRLogin = () => {
  timer = window.setInterval(() => {
    console.log(timer)
    axios({
      url: "/api/QRLogin/" + RYD_LoginId,
      method: "Get"
    }).then(res => {
      if (res != "" && res != null) {
        location.href = "http://hrms.ryderems.com/itsm.html?code=" + res;
      }

    })
  }, 1000)
}

const { width, height } = useWindowSize();

let size = ref(width.value * 0.3);

watch([width, height], () => {
  size.value = width.value * 0.3;
});
</script>
// setTimeout(() => {

//   location.replace("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaa3744f6b6f630f2&redirect_uri=http://hrms.ryderems.com/itsm.html&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect");

// }, 1000);
// console.log(2);
// // eslint-disable-next-line no-unused-vars
// let a = { foo: "" };
// var nanoid = inject("nanoid");
// // eslint-disable-next-line no-unused-vars
// let id = nanoid(36);
// console.log("🚀 ~ file: HomeView.vue ~ line 27 ~ id", id)
// // eslint-disable-next-line no-unused-vars
// let EquipmentInfo = navigator.userAgent;
// let randomStr = ref(random(1).toString());
// //把异步执行的代码放到这里去
// let randomIn = setInterval(() => {
//   randomStr.value = random(1).toString();

// }, 100);
// // eslint-disable-next-line no-unused-vars
// let clickBtn = () => {
//   clearInterval(randomIn);
// };
